﻿using System;

namespace Program09
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入一个整数：");
            if (int.TryParse(Console.ReadLine(), out int num))
            {
                Console.WriteLine("\r\n递归：1*2...*n的结果：" + Number(num));

                Console.WriteLine("\r\n普通方法：1*2...*n的结果：" + Number2(num));
            }
           Console.ReadLine();
        }
        /// <summary>
        /// 用递归实现阶乘
        /// </summary>
        /// <param name="num"></param>
        /// <returns></returns>
        public static int Number(int num)
        {
            if (num == 1)
            {
                return num;
            }
            return Number(num - 1)*num;
        }
        /// <summary>
        /// 用普通方法实现阶乘
        /// </summary>
        /// <param name="num"></param>
        /// <returns></returns>
        public static int Number2(int num)
        {
            int sum = 1;
            if (num == 1)
            {
                return num;
            }
            else
            {
                for (int i = 1; i <= num; i++)
                {
                    sum *= i;
                }
            }
            return sum;
        }
    }
}

